﻿using AMAP.Areas.Client.Models.Home;
using AMAP.ServiceInterfaces;
using System.Web.Mvc;

namespace AMAP.Areas.Client.Controllers
{
    public class HomeController : Controller
    {
        private IClientService ClientService;

        public HomeController(IClientService ClientService)
        {
            this.ClientService = ClientService;
        }

        [Authorize(Roles="Client")]
        public ActionResult Index()
        {
            ClientHomeIndexViewModel Model = new ClientHomeIndexViewModel();
            Model.Client = this.ClientService.GetByEmail(User.Identity.Name);
            if (Model.Client.User.Coordinates != null)
                Model.DeliveryDistance = GeoCoder.GetDistance(Model.Client.User.Coordinates, Model.Client.Place);
            else
                Model.DeliveryDistance = 0;

            return View(Model);
        }

    }
}
